#!/usr/bin/php
<?php declare (ticks = 1);
	function RecInclude ($Name) {
		if (is_readable ($Name)) {
			if (is_dir ($Name)) { // files first
				foreach (glob ("$Name/*.php") as $NextLevel) if (! is_dir ($NextLevel)) include_once ($NextLevel);
				foreach (glob ("$Name/*", GLOB_ONLYDIR) as $NextLevel) call_user_func (__FUNCTION__, $NextLevel);
			} else include_once ($Name);
		}
	}
	function HasInterface ($Class, $Interface) {return (in_array ($Interface, class_implements ($Class)));}
	ini_set ('display_errors', 1);
	ini_set ('log_errors', 0);
	error_reporting (E_ALL | E_STRICT);
	setlocale (LC_ALL, 'C');
	RecInclude ('/usr/lib/overwatch');
	$ExtMissing = array ();
	foreach (get_declared_classes () as $Class) if (HasInterface ($Class, 'iExtensionsRequired')) {
		is_array ($Exts = call_user_func (array ($Class, '__GetRequiredExtensions'))) or $Exts = array ($Exts);
		foreach ($Exts as $Ext) extension_loaded ($Ext) or array_push ($ExtMissing, $Ext);
	}
	count ($ExtMissing) and trigger_error ('Extensions missing: '.implode (', ', $ExtMissing), E_USER_ERROR);
	Options::Init       ();
	Daemon::Detach      ();
	Daemon::ParseConfig ();
	Daemon::SigHandler  ();
	Daemon::Main        ();
?>
